﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cosmos.Hardware;
using System.Threading;
using System.Drawing;

namespace Previewer
{
    public class MainPreview
    {
        public static void Init()
        {
            VGAScreen.SetMode320x200x8();
            for (int i = 0; i < VGAScreen.Colors; i++)
            {
                int ii = (255 / VGAScreen.Colors) * i;
                VGAScreen.SetPaletteEntry(i, Color.FromArgb(ii, ii, ii));
            }

            uint startX = 0, startY = 0, offsetX = 0, offsetY = 0, width = 160, height = 80;

            Random r = new Random();

            uint color = 0;

            bool gscale = true;

            uint amount = 20;

            Cosmos.Debug.Debugger.Send("Drawing...");
            while (offsetX < width)
            {
                uint x = offsetX + startX;
                offsetY = 0;

                Cosmos.Debug.Debugger.Send("X: " + (startX + offsetX) + ", drawing line");

                if (amount == width / VGAScreen.Colors)
                {
                    if (color == VGAScreen.Colors - 1) gscale = false;

                    if (!gscale)
                    {
                        color = (uint)r.Next(1, VGAScreen.Colors - 1);
                    }
                    else
                    {
                        color++;
                    }
                    amount = 0;
                }
                amount++;

                while (offsetY < height)
                {
                    uint y = offsetY + startY;
                    VGAScreen.SetPixel(x, y, color);
                    offsetY++;
                }
                offsetX++;
            }
        }
    }
}
